﻿using System;

namespace Fluffy.Library.Utils
{
	public static class TitleUtils
	{
		public static string GetTitleForSize(long length)
		{
			double size = Convert.ToDouble(length);
			return GetTitleForSize(size);
		}

		public static string GetTitleForSize(ulong length)
		{
			double size = Convert.ToDouble(length);
			return GetTitleForSize(size);
		}

		public static string GetTitleForSize(double size)
		{
			for (int k = 0; k < 4; k++)
			{
				if (size >= 1024)
				{
					size /= 1024D;
					continue;
				}

				switch (k)
				{
					case 0: return string.Format("{0:F0} B", size);
					case 1: return string.Format("{0:F2} Kb", size);
					case 2: return string.Format("{0:F2} Mb", size);
					case 3: return string.Format("{0:F2} Gb", size);
				}
			}

			return string.Format("{0:F2} Tb", size);
		}
	}
}
